package cn.humaohua.study.yanmo_design_pattern.ch12.v1;

public class Main {
    public static void main(String[] args) {
        // 观察者
        Observer reader1 = new Reader("reader1");
        Observer reader2 = new Reader("reader2");
        Observer reader3 = new Reader("reader3");

        // 被观察者
        NewsPaper newsPaper = new NewsPaper();

        // 为补观察者设置观察者
        newsPaper.attach(reader1);
        newsPaper.attach(reader2);
        newsPaper.attach(reader3);

        // 被观察者改变，观察者接收到通知，并处理
        newsPaper.setContent("世界真不太平");

        System.out.println("---------减少一个观察者----------");

        // 移除一个观察者
        newsPaper.detach(reader3);
        // 更改，看通知对象是否有改变
        newsPaper.setContent("世界上还是有好人的");
    }
}
